package com.gfxy.modules.common.controller;

import com.gfxy.modules.GfxyUtils;
import com.gfxy.modules.common.service.IStaffTreeService;
import com.gfxy.modules.system.model.SysDepartTreeModel;
import lombok.extern.slf4j.Slf4j;
import org.jeecg.common.api.vo.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * @author: lijixin 2021/10/6 7:40 下午
 */
@RestController
@RequestMapping("/common/staffTree")
@Slf4j
public class StaffTreeController {

    @Autowired
    private IStaffTreeService staffTreeService;
    /**
     * 查询数据 查出所有部门,并以树结构数据格式响应给前端
     *
     * @return
     */
    @RequestMapping(value = "/queryEducationTreeList", method = RequestMethod.GET)
    public Result<List<SysDepartTreeModel>> queryTreeList(HttpServletRequest req) {

        String rolesStr = GfxyUtils.getRoles(req);

        Result<List<SysDepartTreeModel>> result = new Result<>();
        try {
            List<SysDepartTreeModel> list = staffTreeService.queryEducationDepTreeList();
            result.setResult(list);
            result.setSuccess(true);
//            if(this.isAllDataPermission(rolesStr)){
//                List<SysDepartTreeModel> list = staffTreeService.queryEducationDepTreeList();
//                result.setResult(list);
//                result.setSuccess(true);
//            } else {
//                String orgCode = GfxyUtils.getOrgCode(req);
//                List<SysDepartTreeModel> list = staffTreeService.queryEducationDepTreeListByOrgCode(orgCode);
//                result.setResult(list);
//                result.setSuccess(true);
//            }
        } catch (Exception e) {
            log.error(e.getMessage(),e);
        }
        return result;
    }


    private boolean isAllDataPermission(String rolesStr){

//        return rolesStr.contains("master-operater") || rolesStr.contains("school-leader") || rolesStr.contains("admin");
        return true;
    }
}
